home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / d_vibmembr.pro < prev    next >
Text File  |  1997-07-08  |  71KB  |  1,976 lines

  1. $Id: d_vibmembr.pro,v 1.19 1997/04/19 22:48:46 tremblay Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       d_vibmembr.pro
  9. ;
  10. ;  CALLING SEQUENCE: d_vibmembr
  11. ;
  12. ;  PURPOSE:
  13. ;       Shows an animation of a vibrating membrane in IDL 5.0.
  14. ;
  15. ;  MAJOR TOPICS: Visualization.
  16. ;
  17. ;  CATEGORY:
  18. ;       IDL 5.0
  19. ;
  20. ;  INTERNAL FUNCTIONS and PROCEDURES:
  21. ;       pro vib_setShades           - Set the shading colors overlay
  22. ;       fun toggle_state        - Toggle  off/on name
  23. ;       fun cw_iat              - Compound widget : animation tool in 5.0
  24. ;       pro vibmembr_Event      - Event handler
  25. ;       pro vibmembr_Cleanup    - Cleanup
  26. ;       pro d_vibmembr               - Main procedure
  27. ;
  28. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  29. ;       pro iniobj              - Create the objects
  30. ;       pro vibmem              - Compute the vibrating membrane (main surface)
  31. ;       pro bumps               - Compute 2-D wave data set for shading color
  32. ;       pro cw_iat              - Compound widget animation tool in 5.0.
  33. ;       pro trackball__define   - Create the trackball object
  34. ;       fun gettips             - Read the tip file
  35. ;       pro widtips             - Create the tip widgets text
  36. ;       pro sizetips            - Size the tip widgets text
  37. ;       pro trackball__define   - Create the trackball object
  38. ;       vibmembr.txt
  39. ;       vibmembr.tip
  40. ;
  41. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  42. ;
  43. ;  NAMED STRUCTURES:
  44. ;       none.
  45. ;
  46. ;  COMMON BLOCS:
  47. ;       none.
  48. ;
  49. ;  MODIFICATION HISTORY: Written by DAT,RSI,  July 1996 New GUI
  50. ;                        vibmem.pro written by Steve Kranock, RSI, 1996
  51. ;
  52. ;-
  53. ; -----------------------------------------------------------------------------
  54. ;
  55. ;  Purpose:  Set the shading colors.
  56. ;            This procedure changes the vertices (shades) colors. When
  57. ;            the input initial is less that final, the colors are those
  58. ;            that corresponds to the surface height ( 4-D). Otherwise,
  59. ;            the colors frames are set in an inverse order ( this gives a
  60. ;            6-D mode.
  61. ;
  62.  
  63. FUNCTION bumps,  $
  64.     kindex      ; IN: time index
  65.     
  66.     ;  Create a 2-d time dependent wave function.
  67.     ;
  68.     ;  2 harmonics in th x direction,
  69.     ;  2 harmonics in th y direction
  70.     ;  the z direction is the product of
  71.     ;  the x and y waves...
  72.     ;
  73.  
  74.     ;  Initialize constants
  75.     ;
  76.     kvect = fltarr(4)
  77.     kvect = [10.0, 16.4, 13.0, 11.4]
  78.     kvect = kvect/200 
  79.  
  80.     k = kindex
  81.  
  82.     time =   2.05 * !pi* (0.6 - 0.3*cos(float(k)/100.))
  83.  
  84.     nk = float(k)/10.0 * (-0.7) 
  85.  
  86.     ;  The data set has diumension  ndim x ndim.
  87.     ;
  88.     ndim = 21
  89.  
  90.     wvect = kvect * time
  91.  
  92.     a1 = 1.0
  93.     a2 = 1.0
  94.     a3 = 1.0
  95.     a4 = 1.0
  96.     b1 = 1.0
  97.     b2 = 1.0
  98.     b3 = 1.0
  99.     b4 = 1.0
  100.  
  101.     x = FINDGEN(ndim)*2
  102.     y = FINDGEN(ndim)*2
  103.     z = fltarr(ndim,ndim)
  104.  
  105.     z = z - z
  106.  
  107.     for i = 0, ndim-1 do begin
  108.         for j = 0, ndim-1  do begin
  109.              z(i,j) = z(i,j) + (  a1*cos(wvect(0)*x(i)+nk) + $    
  110.                    b1*sin(wvect(0)*x(i)+nk) + $    
  111.                    a2*cos(wvect(1)*x(i)+nk) + $    
  112.                    b2*sin(wvect(1)*x(i)+nk)  ) *  $
  113.                   (a3*cos(wvect(2)*y(j)+2.0*nk) + $    
  114.                    b3*sin(wvect(2)*y(j)+2.0*nk) + $    
  115.                    a4*cos(wvect(3)*y(j)+2.0*nk) + $    
  116.                    b4*sin(wvect(3)*y(j)+2.0*nk)  ) 
  117.         endfor
  118.     endfor
  119.          
  120.     RETURN, z
  121.  
  122. end   ;
  123.  
  124. ; $Id: cw_iat.pro,v 
  125. ;
  126. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  127. ;       Unauthorized reproduction prohibited.
  128. ;
  129. ;+
  130. ;  FILE:
  131. ;       cw_iat.pro
  132. ;
  133. ;  CALLING SEQUENCE: cw_iat
  134. ;
  135. ;  PURPOSE:
  136. ;       Compoihnd widget of the animation tool in IDL 5.0.
  137. ;
  138. ;  MAJOR TOPICS: Visualization and animation.
  139. ;
  140. ;  CATEGORY:
  141. ;       IDL 5.0
  142. ;
  143. ;  INTERNAL FUNCTIONS and PROCEDURES:
  144. ;       fun getRotation         - Rotation values of the satellite
  145. ;       fun createSatellite     - create the satellite object
  146. ;       fun findE               - Compute the eccentric anomaly
  147. ;       fun findPosition        - Compute the satelitte's ephemeris.
  148. ;       pro orbit_Event         - Event handler
  149. ;       pro orbit_Cleanup       - Cleanup
  150. ;       pro orbit               - Main procedure
  151. ;
  152. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  153. ;       pro trackball__define   - Create the trackball object
  154. ;
  155. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  156. ;
  157. ;  NAMED STRUCTURES:
  158. ;       none.
  159. ;
  160. ;  COMMON BLOCS:
  161. ;       none.
  162. ;
  163. ;  MODIFICATION HISTORY: Written by DAT,RSI,  July 1996 New GUI
  164. ;                        Modified by DAT, RSI, february 1997, add 
  165. ;                        trackball object and cleanup the code.
  166. ;
  167. ;-
  168. ;---------------------------------------------------------------------------
  169. ;
  170. ;  Purpose:  On realization of the main base (outside this CW), assigns
  171. ;            the widow object to the parent of the widget draw.
  172. ;
  173. pro DRAW1CB, $
  174.     sEvent      ; IN: event structure.
  175.  
  176.     WIDGET_CONTROL, sEvent, GET_VALUE = oWindow
  177.     wRightBase = WIDGET_INFO(sEvent, /PARENT)
  178.     WIDGET_CONTROL, wRightBase, SET_UVALUE =oWindow , /NO_COPY
  179. end
  180.  
  181. ;---------------------------------------------------------------------------
  182. ;
  183. ;  Purpose:  Event handler for events occuring within the compound widget.
  184. ;            these event are : bitmap buttons, frame speed slider,
  185. ;            frame indicator slider, and the reset button.
  186. ;
  187. pro cw_iatEvent, $
  188.     sEvent      ; IN: event structure.
  189.  
  190.     ;  Get the drawWindow object identifier
  191.     ;  which is the user value of the right base.
  192.     ;
  193.     child = WIDGET_INFO(sEvent.handler, /CHILD)
  194.     WIDGET_CONTROL, child, GET_UVALUE = sState, /NO_COPY
  195.     WIDGET_CONTROL, sState.wRightBase, $
  196.         GET_UVALUE=temp, /NO_COPY
  197.     oWindow = temp
  198.     WIDGET_CONTROL, sState.wRightBase, $
  199.         SET_UVALUE=temp, /NO_COPY
  200.     WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  201.  
  202.     WIDGET_CONTROL, sEvent.id, GET_UVALUE= uValue
  203.  
  204.     ;  Branch to the appropriate event.
  205.     ;
  206.     case uValue of 
  207.         'ACTIVE' : begin
  208.  
  209.             ;  Toggle the active button.
  210.             ;
  211.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  212.             WIDGET_CONTROL, sState.wActiveButton, GET_VALUE=activeFlag
  213.             sState.activeFlag = activeFlag
  214.  
  215.             if (sState.activeFlag EQ 1) then begin
  216.                 WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  217.                    SET_VALUE=sState.frameIndex
  218.  
  219.                 if (sState.stopFlag EQ 1)  then begin
  220.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  221.                         SENSITIVE=1
  222.                 endif
  223.             endif else begin
  224.                 WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  225.                     SENSITIVE=0
  226.             endelse
  227.  
  228.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  229.  
  230.         end     ;  of  ACTIVE
  231.  
  232.         ;  The timer event create the loop because another timer event
  233.         ;  is generated given that the stop button has not been pushed.
  234.         ;
  235.         'TIMER' : begin
  236.  
  237.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  238.  
  239.             stopFlag = sState.stopFlag
  240.  
  241.             ;  Animate only if the stop flag has not been pushed
  242.             ;  ( i.e. stopflag = 0).
  243.             ; 
  244.             if (stopFlag EQ 0) then begin
  245.  
  246.                 ;  Hide the previous frame (model).
  247.                 ;
  248.                 i = sState.previousIndex
  249.                 sState.oMovableModelArray(i)->SetProperty, HIDE=1
  250.                 sState.oStaticModelArray(i)->SetProperty, HIDE=1
  251.  
  252.                 sState.frameIndex = sState.frameIndex + $
  253.                     sState.frameIncrement
  254.                 sState.currentIndex = sState.frameIndex
  255.                 if (sState.cycleFlag EQ 0 ) then begin
  256.                     ;  Reset the frame index , First if not in cycle mode.
  257.                     ;
  258.                     if (sState.frameIndex EQ sState.nframes) then begin
  259.                         sState.frameIndex = 0
  260.                     endif
  261.                     if (sState.frameIndex LT 0) then begin
  262.                         sState.frameIndex = sState.nframes-1
  263.                     endif
  264.                 endif else begin  
  265.                     ;  Reset the frame index if in
  266.                     ;  cycle mode ( back and forth).
  267.                     ;
  268.                     if (( sState.frameIndex EQ (sState.nframes)) OR $
  269.                         (sState.frameIndex EQ -1) ) then begin
  270.                         sState.frameIncrement = -sState.frameIncrement
  271.                         sState.frameIndex = sState.frameIndex + $
  272.                             2*sState.frameIncrement
  273.                     endif
  274.                 endelse
  275.  
  276.                 ;  Draw the current frame.
  277.                 ;
  278.                 i = sState.frameIndex
  279.                 sState.oMovableModelArray(i)->SetProperty, HIDE=0
  280.                 sState.oStaticModelArray(i)->SetProperty, HIDE=0
  281.                 oWindow->Draw, sState.oView
  282.                 sState.previousIndex = i
  283.  
  284.                 if (sState.activeFlag EQ 1) then begin
  285.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  286.                         SET_VALUE= sState.frameIndex
  287.                 endif
  288.  
  289.                 ;  Accumulate the number of frames to compute
  290.                 ;  the frame rate.
  291.                 ;
  292.                 sState.count = sState.count + 1
  293.  
  294.                 ;  If count is 5 , reset it zero,
  295.                 ;  Display the frame rate.
  296.                 ;
  297.                 if (sState.count EQ 5) then begin
  298.                     sState.finalTime = SYSTIME(1)
  299.                     delta = sState.finalTime - sState.startTime
  300.                     rate = FLOAT(5.0/ delta)
  301.                     WIDGET_CONTROL, sState.wFramesRateLabel, $
  302.                        SET_VALUE= STRING(rate, FORMAT='(f6.2)' )
  303.                     sState.count = 0
  304.                     sState.startTime = sState.finalTime
  305.                 endif
  306.  
  307.                 WIDGET_CONTROL, sState.wButtonBase, $
  308.                     TIMER=1.0e-4 + sState.delay
  309.                 sState.previousIndex = sState.frameIndex
  310.  
  311.             endif  ; of StopFlag = 0
  312.  
  313.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  314.  
  315.         end     ;   of  TIMER
  316.  
  317.         ;  Handle the play forward button.
  318.         ;
  319.         'PLAYFORWARD' : begin
  320.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  321.             if( sState.forwardFlag EQ 0) then begin
  322.                 if(sState.stopflag EQ 1) then begin
  323.                     sState.count = 0
  324.                     sState.startTime = systime(1)
  325.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  326.                         SENSITIVE=0
  327.                 endif
  328.  
  329.                 sState.frameIncrement = 1
  330.                 sState.cycleFlag = 0
  331.                 sState.forwardFlag = 1
  332.                 sState.backwardFlag = 0
  333.                 sState.stopFlag = 0    
  334.                 if (sState.frameIndex EQ sState.nframes-1) $
  335.                     then sState.frameIndex = 0
  336.                 ;  The stop button has not been pushed.
  337.                 ;
  338.                 sState.stopFlag = 0  
  339.                 WIDGET_CONTROL, sState.wplayFButton, $
  340.                     SET_VALUE=sState.BMB.forwardOn
  341.                 WIDGET_CONTROL, sState.wplayBButton, $
  342.                     SET_VALUE=sState.BMB.backward
  343.                 WIDGET_CONTROL, sState.wCycleButton, $
  344.                     SET_VALUE=sState.BMB.cycle
  345.                 WIDGET_CONTROL, sState.wStopButton, $
  346.                     SET_VALUE=sState.BMB.stop
  347.                 WIDGET_CONTROL, sState.wButtonBase, $
  348.                     TIMER=1.0e-4 + sState.delay
  349.             endif
  350.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  351.         end   ; of PLAYFORWARD
  352.  
  353.         ;  Handle the play forward button.
  354.         ;
  355.         'PLAYBACKWARD' : begin
  356.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  357.             if (sState.backwardFlag EQ 0) then begin
  358.                 if (sState.frameIndex EQ 0) then $
  359.                     sState.frameIndex = sState.nframes-1
  360.                 if(sState.stopflag EQ 1) then begin
  361.                     sState.count = 0
  362.                     sState.startTime = systime(1)
  363.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  364.                         SENSITIVE=0
  365.                 endif
  366.  
  367.                 sState.cycleFlag = 0
  368.                 sState.forwardFlag = 0
  369.                 sState.backwardFlag = 1
  370.                 sState.stopFlag = 0    
  371.                 sState.frameIncrement = -1
  372.                 WIDGET_CONTROL, sState.wplayFButton, $
  373.                     SET_VALUE=sState.BMB.forward
  374.                 WIDGET_CONTROL, sState.wplayBButton, $
  375.                     SET_VALUE=sState.BMB.backwardOn
  376.                 WIDGET_CONTROL, sState.wCycleButton, $
  377.                     SET_VALUE=sState.BMB.cycle
  378.                 WIDGET_CONTROL, sState.wStopButton, $
  379.                     SET_VALUE=sState.BMB.stop
  380.                 WIDGET_CONTROL, sState.wButtonBase, $
  381.                     TIMER=1.0e-4 + sState.delay
  382.             endif
  383.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  384.         end   ; of PLAYBACKWARD
  385.  
  386.         ;  Handle the top button(stops the animation).
  387.         ;
  388.         'STOP' : begin
  389.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  390.             if( sState.stopFlag EQ 0) then begin
  391.                 sState.cycleFlag = 0
  392.                 sState.forwardFlag = 0
  393.                 sState.backwardFlag = 0
  394.                 sState.stopFlag = 1    
  395.                 WIDGET_CONTROL, sState.wAreaDraw, DRAW_MOTION = 0
  396.                 WIDGET_CONTROL, sState.wplayFButton, $
  397.                     SET_VALUE=sState.BMB.forward
  398.                 WIDGET_CONTROL, sState.wplayBButton, $
  399.                     SET_VALUE=sState.BMB.backward
  400.                 WIDGET_CONTROL, sState.wCycleButton, $
  401.                     SET_VALUE=sState.BMB.cycle
  402.                 WIDGET_CONTROL, sState.wStopButton, $
  403.                     SET_VALUE=sState.BMB.stopOn
  404.                 if (sState.wResetButton NE 0L) then begin
  405.                     WIDGET_CONTROL, sState.wResetButton, SENSITIVE=1
  406.                 endif
  407.                 if (sState.activeFlag EQ 1) then begin
  408.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  409.                         SENSITIVE=1
  410.                 endif else begin
  411.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  412.                         SENSITIVE=0
  413.                 endelse
  414.             endif
  415.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  416.             RETURN
  417.         end  ; of STOP
  418.  
  419.         ;  Play back and forth (cycle) button.
  420.         ;
  421.         'CYCLE' : begin
  422.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  423.             if (sState.cycleFlag EQ 0) then begin
  424.                 if (sState.stopflag EQ 1) then begin
  425.                     sState.count = 0
  426.                     sState.startTime = SYSTIME(1)
  427.                     WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  428.                         SENSITIVE=0
  429.                 endif
  430.                 sState.cycleFlag = 1
  431.                 sState.forwardFlag = 0
  432.                 sState.backwardFlag = 0
  433.                 sState.stopFlag = 0    
  434.                 WIDGET_CONTROL, sState.wplayFButton, $
  435.                     SET_VALUE=sState.BMB.forward
  436.                 WIDGET_CONTROL, sState.wplayBButton, $
  437.                     SET_VALUE=sState.BMB.backward
  438.                 WIDGET_CONTROL, sState.wCycleButton, $
  439.                     SET_VALUE=sState.BMB.cycleOn
  440.                 WIDGET_CONTROL, sState.wStopButton, $
  441.                     SET_VALUE=sState.BMB.stop
  442.                 WIDGET_CONTROL, sState.wButtonBase, $
  443.                     TIMER=1.0e-4 + sState.delay
  444.             endif
  445.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  446.         end   ; of CYCLE
  447.  
  448.         ;  Reset the initial orientation of the display and
  449.         ;  show the first frame (frame index = 0).
  450.         ;
  451.         'RESET': begin
  452.  
  453.             ;  Reset to the first frame (if play mode was forward), or
  454.             ;  to the last frame ( if play mode was backward). Also
  455.             ;  restore the initial tranformation matrix.
  456.             ;
  457.             WIDGET_CONTROL, child, GET_UVALUE = sState, /NO_COPY
  458.  
  459.             if (sState.frameIncrement EQ 1) then begin
  460.                 sState.frameIndex = 0
  461.                 WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  462.                     SET_VALUE=0
  463.                 i = 0
  464.             endif else begin
  465.                 sState.frameIndex = sState.nframes-1
  466.                 i = sState.nframes-1
  467.                 WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  468.                     SET_VALUE = sState.nframes-1
  469.             endelse
  470.  
  471.             j=i
  472.             sState.oMovableRotationModel->SetProperty, $
  473.                 TRANSFORM=sState.initTransform
  474.             for i = 0, sState.nframes - 1 do begin
  475.                 sState.oMovableModelArray(i)->SetProperty, HIDE=1
  476.                 sState.oStaticModelArray(i)->SetProperty, HIDE=1
  477.             endfor
  478.  
  479.             sState.oMovableModelArray(j)->SetProperty, HIDE=0
  480.  
  481.             sState.oStaticModelArray(j)->SetProperty, HIDE=0
  482.             sState.previousIndex = j
  483.             oWindow->Draw, sState.oView
  484.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  485.         end   ; of RESET
  486.  
  487.         ;  Responds for cursor event in the draw area.
  488.         ;
  489.         'DRAWING': begin
  490.  
  491.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  492.  
  493.             ;  Expose.
  494.             ;
  495.             if (sEvent.type EQ 4) then begin
  496.                 oWindow->Draw, sState.oView
  497.                 WIDGET_CONTROL, child, SET_UVALUE = sState, /NO_COPY
  498.                 RETURN
  499.             endif
  500.  
  501.             ;  Handle trackball update.
  502.             ;
  503.             bHaveTransform = sState.oTrack->Update(sEvent, $
  504.                 TRANSFORM=qmat)
  505.             if (bHaveTransform NE 0) then begin
  506.                 sState.oMovableRotationModel->GetProperty, TRANSFORM=t
  507.                 mt = t # qmat
  508.                 sState.oMovableRotationModel->SetProperty, TRANSFORM=mt
  509.             endif
  510.  
  511.             ;  Handle button press here.
  512.             ;
  513.             if (sEvent.type EQ 0) then begin
  514.                 sState.btndown = 1B
  515.                 oWindow->SetProperty, QUALITY=sState.dragq
  516.                 WIDGET_CONTROL,sState.wAreaDraw, /DRAW_MOTION
  517.             endif
  518.  
  519.             ;  Handle draw motion here.
  520.             ;
  521.             if ((sEvent.type EQ 2) and (sState.btndown EQ 1b)) $
  522.                 then begin
  523.                 if (bHaveTransform) then $
  524.                     oWindow->Draw, sState.oView
  525.             endif
  526.  
  527.             ;  Handle release button here.
  528.             ;
  529.             if (sEvent.type EQ 1) then begin
  530.                 if (sState.btndown EQ 1B) then begin
  531.                     oWindow->SetProperty, QUALITY=2
  532.                     oWindow->Draw, sState.oView
  533.                 endif
  534.                 sState.btndown = 0B
  535.                 WIDGET_CONTROL, sState.wAreaDraw, DRAW_MOTION=0
  536.             endif
  537.  
  538.             WIDGET_CONTROL, child, SET_UVALUE = sState, /NO_COPY
  539.  
  540.         end   ; of DRAWING
  541.  
  542.         ;  Reset the delay between frames using the speed slider.
  543.         ;
  544.         'SPEED' : begin
  545.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  546.             WIDGET_CONTROL, sState.wFramesSpeedSlider, $
  547.                 GET_VALUE=speedvalue
  548.             if (speedvalue EQ 100) then begin
  549.                 sState.delay = 0.0
  550.             endif else begin
  551.                 sState.delay = 3.0 / (3.0 + speedvalue )
  552.             endelse
  553.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  554.         end    ;  of SPEED
  555.  
  556.         ;  Display the frame selected by the indicator slider.
  557.         ;
  558.         'INDICATOR': begin
  559.             WIDGET_CONTROL, child, GET_UVALUE=sState, /NO_COPY
  560.             wCWBase = sState.wCWBase
  561.             WIDGET_CONTROL, sState.wFramesIndicatorSlider, $
  562.                 GET_VALUE = frameIndex
  563.  
  564.             i = sState.previousIndex
  565.             sState.oMovableModelArray(i)->SetProperty, HIDE=1
  566.             sState.oStaticModelArray(i)->SetProperty, HIDE=1
  567.  
  568.             sState.frameIndex = frameIndex
  569.             sState.previousIndex = frameIndex
  570.             sState.oMovableModelArray(frameIndex)->SetProperty, HIDE=0
  571.             sState.oStaticModelArray(frameIndex)->SetProperty, HIDE=0
  572.             oWindow->Draw, sState.oView
  573.             WIDGET_CONTROL, child, SET_UVALUE=sState, /NO_COPY
  574.  
  575.             ;  We may return here because the  frame indicator slider
  576.             ;  is not sensitized while in a playing mode. 
  577.             ;
  578.             RETURN
  579.         end   ; of INDICATOR
  580.  
  581.     endcase   ; of case widget_info(name)
  582.  
  583. end  ; of cw_iatEvent
  584.  
  585. ;---------------------------------------------------------------------------
  586. ;
  587. ;  Purpose:  Initialize (create) the bitmap buttons.
  588. ;
  589. function InitBitmapButtons
  590.  
  591.     stop = [[000B, 000B, 000B],[000B, 000B, 000B],$
  592.             [000B, 000B, 000B],[000B, 000B, 000B],$
  593.             [240B, 255B, 015B],[240B, 255B, 015B],$
  594.             [240B, 255B, 015B],[112B, 000B, 014B],$
  595.             [112B, 255B, 014B],[112B, 255B, 014B],$
  596.             [112B, 255B, 014B],[112B, 255B, 014B],$
  597.             [112B, 255B, 014B],[112B, 255B, 014B],$
  598.             [112B, 255B, 014B],[112B, 255B, 014B],$
  599.             [112B, 000B, 014B],[240B, 255B, 015B],$
  600.             [240B, 255B, 015B],[240B, 255B, 015B],$
  601.             [000B, 000B, 000B],[000B, 000B, 000B],$
  602.             [000B, 000B, 000B],[000B, 000B, 000B]]
  603.  
  604.     stopon = [[255B, 255B, 255B],[255B, 255B, 255B],$
  605.               [255B, 255B, 255B],[255B, 255B, 255B],$
  606.               [015B, 000B, 240B],[015B, 000B, 240B],$
  607.               [015B, 000B, 240B],[143B, 255B, 241B],$
  608.               [143B, 000B, 241B],[143B, 000B, 241B],$
  609.               [143B, 000B, 241B],[143B, 000B, 241B],$
  610.               [143B, 000B, 241B],[143B, 000B, 241B],$
  611.               [143B, 000B, 241B],[143B, 000B, 241B],$
  612.               [143B, 255B, 241B],[015B, 000B, 240B],$
  613.               [015B, 000B, 240B],[015B, 000B, 240B],$
  614.               [255B, 255B, 255B],[255B, 255B, 255B],$
  615.               [255B, 255B, 255B],[255B, 255B, 255B]]
  616.  
  617.     forward = [[000B, 000B, 000B],[000B, 000B, 000B],$
  618.                [000B, 000B, 000B],[056B, 000B, 000B],$
  619.                [248B, 000B, 000B],[248B, 003B, 000B],$
  620.                [248B, 015B, 000B],[248B, 063B, 000B],$
  621.                [248B, 255B, 000B],[248B, 255B, 003B],$
  622.                [248B, 255B, 015B],[248B, 255B, 031B],$
  623.                [248B, 255B, 031B],[248B, 255B, 015B],$
  624.                [248B, 255B, 003B],[248B, 255B, 000B],$
  625.                [248B, 063B, 000B],[248B, 015B, 000B],$
  626.                [248B, 003B, 000B],[248B, 000B, 000B],$
  627.                [056B, 000B, 000B],[000B, 000B, 000B],$
  628.                [000B, 000B, 000B],[000B, 000B, 000B]]
  629.  
  630.     forwardOn = [[255B, 255B, 255B],[255B, 255B, 255B],$
  631.                  [255B, 255B, 255B],[199B, 255B, 255B],$
  632.                  [007B, 255B, 255B],[007B, 252B, 255B],$
  633.                  [007B, 240B, 255B],[007B, 192B, 255B],$
  634.                  [007B, 000B, 255B],[007B, 000B, 252B],$
  635.                  [007B, 000B, 240B],[007B, 000B, 224B],$
  636.                  [007B, 000B, 224B],[007B, 000B, 240B],$
  637.                  [007B, 000B, 252B],[007B, 000B, 255B],$
  638.                  [007B, 192B, 255B],[007B, 240B, 255B],$
  639.                  [007B, 252B, 255B],[007B, 255B, 255B],$
  640.                  [199B, 255B, 255B],[255B, 255B, 255B],$
  641.                  [255B, 255B, 255B],[255B, 255B, 255B]]
  642.  
  643.     backward = [[000B, 000B, 000B],[000B, 000B, 000B],$
  644.                 [000B, 000B, 000B],[000B, 000B, 028B],$
  645.                 [000B, 000B, 031B],[000B, 192B, 031B],$
  646.                 [000B, 240B, 031B],[000B, 252B, 031B],$
  647.                 [000B, 255B, 031B],[192B, 255B, 031B],$
  648.                 [240B, 255B, 031B],[248B, 255B, 031B],$
  649.                 [248B, 255B, 031B],[240B, 255B, 031B],$
  650.                 [192B, 255B, 031B],[000B, 255B, 031B],$
  651.                 [000B, 252B, 031B],[000B, 240B, 031B],$
  652.                 [000B, 192B, 031B],[000B, 000B, 031B],$
  653.                 [000B, 000B, 028B],[000B, 000B, 000B],$
  654.                 [000B, 000B, 000B],[000B, 000B, 000B]]
  655.  
  656.     backwardOn = [[255B, 255B, 255B],[255B, 255B, 255B],$
  657.                   [255B, 255B, 255B],[255B, 255B, 227B],$
  658.                   [255B, 255B, 224B],[255B, 063B, 224B],$
  659.                   [255B, 015B, 224B],[255B, 003B, 224B],$
  660.                   [255B, 000B, 224B],[063B, 000B, 224B],$
  661.                   [015B, 000B, 224B],[007B, 000B, 224B],$
  662.                   [007B, 000B, 224B],[015B, 000B, 224B],$
  663.                   [063B, 000B, 224B],[255B, 000B, 224B],$
  664.                   [255B, 003B, 224B],[255B, 015B, 224B],$
  665.                   [255B, 063B, 224B],[255B, 255B, 224B],$
  666.                   [255B, 255B, 227B],[255B, 255B, 255B],$
  667.                   [255B, 255B, 255B],[255B, 255B, 255B]]
  668.  
  669.     cycle = [[000B, 000B, 000B], [000B, 000B, 000B], [000B, 128B, 000B], $
  670.              [000B, 128B, 001B], [000B, 128B, 003B], [248B, 255B, 006B], $
  671.              [008B, 000B, 012B], [008B, 000B, 024B], [248B, 255B, 012B], $
  672.              [248B, 255B, 006B], [000B, 128B, 003B], [000B, 129B, 001B], $
  673.              [128B, 129B, 000B], [192B, 001B, 000B], [096B, 255B, 015B], $
  674.              [048B, 000B, 008B], [024B, 000B, 008B], [048B, 255B, 015B], $
  675.              [096B, 255B, 015B], [192B, 001B, 000B], [128B, 001B, 000B], $
  676.              [000B, 001B, 000B], [000B, 000B, 000B], [000B, 000B, 000B] ]
  677.  
  678.     cycleOn = [[255B, 255B, 255B], [255B, 255B, 255B], [255B, 127B, 255B], $
  679.                [255B, 127B, 254B], [255B, 127B, 252B], [007B, 000B, 249B], $
  680.                [247B, 255B, 243B], [247B, 255B, 231B], [007B, 000B, 243B], $
  681.                [007B, 000B, 249B], [255B, 127B, 252B], [255B, 126B, 254B], $
  682.                [127B, 126B, 255B], [063B, 254B, 255B], [159B, 000B, 240B], $
  683.                [207B, 255B, 247B], [231B, 255B, 247B], [207B, 000B, 240B], $
  684.                [159B, 000B, 240B], [063B, 254B, 255B], [127B, 254B, 255B], $
  685.                [255B, 254B, 255B], [255B, 255B, 255B], [255B, 255B, 255B] ]
  686.  
  687.     bitmapbutton = { Stop:stop, Forward:forward, $
  688.         Backward:backward, Cycle:cycle , $
  689.         ForwardOn : forwardOn, $
  690.         BackwardOn : backwardOn, $
  691.         CycleOn : cycleOn, StopOn : stopOn }
  692.  
  693.     RETURN, bitmapButton
  694.  
  695. end  ;  of InitBitmaspButton
  696.  
  697. ;---------------------------------------------------------------------------
  698. ;
  699. ;  Purpose:  This function  is a compound widget that creates the
  700. ;            animation tool for IDL 5.0. It returns the top level
  701. ;            base of this 
  702. ;
  703. ;            The main feature is the interactivity capability.
  704. ;            The object array of oMovableModelArray will be interactive
  705. ;            meaning that the object array can be rotated interactivily
  706. ;            with the clik-drag-release of the left mouse button
  707. ;            suring the animation.
  708. ;            The object array in oStaticModelArray will not be interactive.
  709. ;            However, their content can be different for each frames.
  710. ;
  711. function CW_IAT, $
  712.     wTopBase, $               ; IN: parent base identifier
  713.     oStaticModelArray, $      ; IN: Model array that is not interactive
  714.     oMovableModelArray, $     ; IN: Model array that is interactive
  715.     oMovableModel, $          ; IN: translation model
  716.     oMovableRotationModel, $  ; IN: rotation model
  717.     oMovableScalingModel, $   : IN: scaling model
  718.     oView, $                  ; IN: view 
  719.     oTrack, $                 ; IN: trackball object (must be created outside )
  720.     oContainer, $             ; IN: container object (must be created outside )
  721.     nFrames, $                ; IN: number of frames.
  722.     Xsize = xsize, $          ; IN: (opt) drawing area x size (default =500) 
  723.     Ysize = ysize, $          ; IN: (opt) drawing area y size (default =425)
  724.     Reset = reset, $          ; IN: (opt) createa reset button if set to 1.
  725.     Status = status           ; OUT: returns 0 on failure, 1 on success
  726.  
  727.  
  728.     ;  Set status to OK.
  729.     ; 
  730.     status = 1
  731.  
  732.     ;  Verify that  all the parameters have been correctly
  733.     ;  passed.
  734.     ;
  735.     if (N_Params() NE 10) then begin
  736.         status = 0
  737.         Message, 'ERROR : 10 parameters must be passed to cw_iat.pro'
  738.     endif
  739.  
  740.     ;  Verify that the top level base is valid.
  741.     ;
  742.     check = WIDGET_INFO(wTopBase, /VALID_ID)
  743.     if (check NE 1) then begin
  744.         status = 0
  745.         Message, 'ERROR : Top level base identifer is not valid.'
  746.     endif
  747.  
  748.     ;  Set the default x and y size of the view area if not provided.
  749.     ;
  750.     if (N_ELEMENTS(xsize) EQ 0) then xsize = 500
  751.     if (N_ELEMENTS(ysize) EQ 0) then ysize = 425
  752.    
  753.     ;  Initialize the bitmap buttons (BitMap Button or BMB).
  754.     ;
  755.     BMB = InitBitmapButtons()
  756.  
  757.     ;  Create the cw base, child of the top level base(wTopBase).
  758.     ;
  759.     wCWBase = WIDGET_BASE(wTopBase, COLUMN=2, /FRAME)
  760.  
  761.        ;  Create a base for the left column.
  762.        ;  The left column contains functionality buttons.
  763.        ;
  764.        wLeftBase = WIDGET_BASE(wCWBase, /BASE_ALIGN_CENTER, $
  765.            /COLUMN)
  766.  
  767.            wButtonBase = WIDGET_BASE(wLeftBase, UVALUE='TIMER', /ROW)
  768.  
  769.                wPlayBButton = WIDGET_BUTTON(wButtonBase, $
  770.                    VALUE=BMB.backward, UVALUE='PLAYBACKWARD')
  771.  
  772.                wStopButton = WIDGET_BUTTON(wButtonBase, $
  773.                    VALUE=BMB.stopOn, UVALUE='STOP')
  774.  
  775.                wPlayFButton = WIDGET_BUTTON(wButtonBase, $
  776.                    VALUE=BMB.forward, UVALUE='PLAYFORWARD')
  777.  
  778.                wCycleButton = WIDGET_BUTTON(wButtonBase, $
  779.                    VALUE=BMB.cycle, UVALUE='CYCLE')
  780.  
  781.            wSpeedBase = WIDGET_BASE(wLeftBase, /COLUMN)
  782.  
  783.                wSpeedBaseLabel = WIDGET_LABEL(wSpeedBase, $
  784.                    VALUE = "Animation Speed:")
  785.  
  786.                wFramesSpeedBase = WIDGET_BASE(wSpeedBase, $
  787.                    TITLE = "Animation Speed", /COLUMN, /FRAME)
  788.  
  789.                    wFramesRateBase = WIDGET_BASE(wFramesSpeedBase, /ROW)
  790.  
  791.                        wFramesPerSecLabel = WIDGET_LABEL(wFramesRateBase, $
  792.                            VALUE = "Frames/Sec:")
  793.  
  794.                        wFramesRateLabel = WIDGET_LABEL(wFramesRateBase, $
  795.                            VALUE = '00.00 ')
  796.  
  797.                    wSliderBase = WIDGET_BASE(wFramesSpeedBase, $
  798.                        /COLUMN, /ALIGN_CENTER)
  799.  
  800.                        wfasttLbl = WIDGET_LABEL(wSliderBase, VALUE='Fast', $
  801.                            /ALIGN_CENTER)
  802.  
  803.                        wFramesSpeedSlider = WIDGET_SLIDER(wSliderBase,$
  804.                            /ALIGN_CENTER, $
  805.                            /DRAG, VALUE = 100, UVALUE='SPEED', $
  806.                            MAXIMUM = 100, MINIMUM = 0, /VERTICAL, $
  807.                            /SUPPRESS_VALUE)
  808.  
  809.                        wSlowLbl = WIDGET_LABEL(wSliderBase, VALUE='Slow', $
  810.                            /ALIGN_CENTER)
  811.  
  812.            wFrameBase = WIDGET_BASE(wLeftBase, /COLUMN)
  813.  
  814.                wFrameBaseLabel = WIDGET_LABEL(wFrameBase, $
  815.                    VALUE = "Animation Frame:")
  816.  
  817.                wFrameIndicatorBase = WIDGET_BASE(wFrameBase, $
  818.                    TITLE = "Animation Frame", /COLUMN, /FRAME)
  819.  
  820.                    wFramesIndicatorSlider = WIDGET_SLIDER(wFrameIndicatorBase, $
  821.                        /DRAG, VALUE = 0, UVALUE='INDICATOR', $
  822.                        MAXIMUM = nframes - 1, MINIMUM = 0)
  823.  
  824.                    wActiveButton = CW_BGROUP(wFrameIndicatorBase, $
  825.                        ['Active Slider'], UVALUE='ACTIVE', $
  826.                        FRAME=0, /NONEXCLUSIVE, /RETURN_INDEX, $
  827.                        SET_VALUE=0)                         ; inactive
  828.      
  829.         ;  Create the reset button if the reset keyword is set.
  830.         ;
  831.         if (N_ELEMENTS(reset) NE 0) then begin
  832.             wResetButton = WIDGET_BUTTON(wLeftBase, $
  833.                 VALUE='Reset', UVALUE='RESET')
  834.         endif else begin
  835.             wResetButton = 0L
  836.         endelse
  837.  
  838.         ;  Create a widget base for the right column.
  839.         ;  It contains the drawing area.
  840.         ;
  841.         wRightBase = WIDGET_BASE(wCWBase,/BASE_ALIGN_CENTER, /COLUMN)
  842.  
  843.             wAreaDraw = WIDGET_DRAW(wRightBase, XSIZE=xsize, $
  844.                 GRAPHICS_LEVEL=2, $
  845.                 YSIZE=ysize, /BUTTON_EVENTS, UVALUE='DRAWING', $
  846.                 RETAIN=0, /EXPOSE_EVENT, NOTIFY_REALIZE='Draw1CB')
  847.  
  848.     ;  Initial transform, to be used when reset.
  849.     ;
  850.     oMovableRotationModel->GetProperty, TRANSFORM=initTransform
  851.  
  852.     ;  Get the current time.
  853.     ;
  854.     starttime = systime(1)
  855.  
  856.     ;  Initialize the time delay between frames .
  857.     ;
  858.     delay = 2.0/(1.0 + 100.0)
  859.  
  860.     ;  Initialize the button flags.
  861.     ;
  862.     cycleFlag = 0        ; 0 = not in cycle mode, 1 = is in cycle mode
  863.     forwardFlag = 0      ; 0 = not in play forward mode, 1 = is
  864.     backwardFlag = 0     ; 0 = not in play forward mode, 1 = is
  865.     stopFlag = 1         ; 0 = playing, 1 = stopped
  866.     activeFlag = 0       ; 0 = frame indicator slider not active, 1 = active
  867.  
  868.     ;  Initialize the frame index and icrement.
  869.     ;
  870.     frameIndex = 0
  871.     frameIncrement = 1   ; 1 = play forward , -1 :  play backward
  872.     count = 0            ; for calculating the frame speed rate.
  873.     rate = 0.0
  874.  
  875.     vv = OBJARR(5)
  876.  
  877.     ;  Create the sState.vector. To retrieve it outside cw_iat, do this :
  878.     ;
  879.     ; child = WIDGET_INFO( wCWBASE, /CHILD)
  880.     ; WIDGET_CONTROL, child, GET_UVALUE = state
  881.     ; 
  882.     sState= { $
  883.         CurrentIndex: 0, $             ; Current frame index
  884.         PreviousIndex: 0, $            ; Previous frame index
  885.         btndown: 0b, $                 ; Mouse button: 0=down, other: not down
  886.         dragq: 2, $                    ; Drag quality: 0=low, 1=med. 2=high
  887.         facing: 'BOTH', $              ; Facing both sides
  888.         wAreaDraw: wAreaDraw, $        ; Widget draw ID
  889.         Delay : delay, $               ; Time delay between frames
  890.         OView: oView, $                ; View boject
  891.         OMovableModelArray:  $
  892.             oMovableModelArray, $      ; Models
  893.          OMovableModel: $ 
  894.             oMovableModel, $
  895.         OMovableRotationModel: $
  896.             oMovableRotationModel, $
  897.         OMovableScalingModel: $
  898.             oMovableScalingModel, $
  899.         OStaticModelArray: $
  900.             oStaticModelArray, $
  901.         OContainer: oContainer, $      ; Container object
  902.         OTrack: oTrack, $              ; Trackball object
  903.         WTopBase: wTopBase, $          ; Top level base, parent of wCWBase
  904.         WCWBase: wCWBase, $            ; Top base of cw_iat
  905.         WRightBase: wRightBase, $      ; Parent base of the draw widget ID
  906.         WButtonBase: wButtonBase, $    ; Parent base of the buttons ID
  907.         WLeftBase: wLeftBase, $        ; Left column base ID
  908.         WPlayBButton: wPlayBButton, $  ; Play backward button ID
  909.         WStopButton: wStopButton, $    ; Stop button ID
  910.         WPlayFButton: wPlayFButton, $  ; Play forward button ID
  911.         WCycleButton: wCycleButton, $  ; Play in cycle button ID
  912.         WResetButton: wResetButton, $  ; Rest button ID
  913.         WActiveButton: wActiveButton, $; Active button ID
  914.         WFramesSpeedSlider:  $
  915.             wFramesSpeedSlider, $      ; Animation speed slider ID
  916.         WFramesIndicatorSlider:  $
  917.             wFramesIndicatorSlider, $  ; Frame indicator slider ID
  918.         WFramesRateLabel: $ 
  919.             wFramesRateLabel, $        ; Animation speed label ID
  920.         Nframes: nframes, $            ; Number of frames
  921.         ActiveFlag : activeFlag, $     ; 0=active button off, 1=on
  922.         ForwardFlag : forwardFlag, $   ; Play forward mode: 0=no, 1=yes
  923.         BackwardFlag : backwardFlag, $ ; Play backward mode: 0=no, 1=yes
  924.         StopFlag : stopFlag, $         ; Animation stopped: 0=no, 1=yes 
  925.         CycleFlag : cycleFlag, $       ; Play in cycle: 0=no, 1=yes
  926.         InitTransform : initTransform, $ : Initial transformation
  927.         InitFlag : 0, $                ; Initial flag (1 only at start)
  928.         Count : count, $               ; Count the number of frames
  929.         Rate : rate, $                 ; Animation rate (frames per sec.)
  930.         FrameIndex : FrameIndex, $     ; Current frame index
  931.         FrameIncrement :  $
  932.              FrameIncrement, $         ; Frame index increment
  933.         BMB : BMB, $                   ; Bitmap buttons structure
  934.         StartTime : startTime, $       ; Start time
  935.         FinalTime : startTime $        ; final time (for animation speed)
  936.     }  
  937.  
  938.     ;  Set the sState.as the user value of the first child of
  939.     ;  cCWBase identifier.
  940.     ;  To have access to the 'sState. outside of this compound widget
  941.     ;  do this :
  942.     ;
  943.     ;  child = WIDGET_INFO(wCWBase, /CHILD)
  944.     ;  WIDGET_CONTROL, child, GET_UVALUE = sState. /NO_COPY
  945.     ;
  946.     WIDGET_CONTROL, wLeftBase, SET_UVALUE=sState, /NO_COPY
  947.  
  948.     WIDGET_CONTROL, wCWBase, EVENT_PRO = 'cw_iatEvent'
  949.  
  950.     RETURN, wCWBase
  951.  
  952. end  ; of cw_iat
  953.  
  954. ; -----------------------------------------------------------------------------
  955. ;
  956. ;  Purpose:   Create a vibrating membrane data.
  957. ;
  958. function vibmem, $
  959.     nFrames, $        ; IN:  number of frames
  960.     index             ; IN:  function index (0 =<  index < nFrames)
  961.  
  962.     nx = 21   ; x dimension of the data set.
  963.     ny = 21   ; y dimension of the data set.
  964.  
  965.     x = FIndGen(nx)/(nx-1)
  966.     y = FIndGen(ny)/(ny-1)
  967.  
  968.     x = x # Replicate(1.,ny)
  969.     y = Replicate(1.,nx) # y
  970.  
  971.     data = FLTARR(nx, ny)
  972.     ;  Mode
  973.     ;
  974.     i = 3
  975.     j = 2
  976.     z = sin(i*!Pi*x) * sin(j*!Pi*y)
  977.     
  978.     a = sin(FIndGen(nframes)*2*!Pi/nframes)
  979.     data =  z * a(index)
  980.  
  981.     RETURN, data
  982. end
  983.  
  984.  $Id: d_vibmembr.pro,v 1.19 1997/04/19 22:48:46 tremblay Exp $
  985. ;
  986. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  987. ;       Unauthorized reproduction prohibited.
  988. ;
  989. ;+
  990. ;  FILE:
  991. ;       iniobj.pro
  992. ;
  993. ;  PURPOSE:
  994. ;       This procedure create the objects to be displayed
  995. ;       by the IDL 5.0 animation tool (CW_IAT)
  996. ;
  997. ;  CATEGORY:
  998. ;       IDL 5.0
  999. ;
  1000. ;  CONTENTS:
  1001. ;       pro  iniobj      ; create and returns the objects.
  1002. ;
  1003. ;  NAMED STRUCTURES:
  1004. ;       initStr
  1005. ;
  1006. ;  COMMON BLOCS:
  1007. ;       none.
  1008. ;
  1009. ;  MODIFICATION HISTORY:
  1010. ;       9/96,   DAT   - Written.
  1011. ;-
  1012. ; -----------------------------------------------------------------------------
  1013. ;
  1014. ;  Purpose:  Function returns  the created objects.
  1015. ;
  1016. function iniobj, $
  1017.      nframes, $     ; IN: number of frames
  1018.      xdim, $        ; IN: x dimension of the data
  1019.      ydim, $        ; IN: y dimension of the data
  1020.      box = box      ; IN: (opt) box around the main objects.
  1021.  
  1022.     ;  Initialize parameters.
  1023.     ;
  1024.     boxhere = N_ELEMENTS(box)
  1025.  
  1026.     ; Set the view such that the surface is
  1027.     ; contained within a box defined by
  1028.     ; by radx and rady ( view normal coordinates)
  1029.     ;
  1030.     xAxis = -0.5      ; center the  axes
  1031.     yAxis = -0.5     
  1032.     zAxis = -0.5    
  1033.  
  1034.     sqr3 = sqrt(3)
  1035.     radx = 2.0   ; viewport in normal coor.
  1036.     rady = 2.0
  1037.     xv = (1.0 - sqr3) /(2.0 * radx)
  1038.     yv = (1.0 - sqr3) /(2.0 * rady)
  1039.     width = 1.0 - 2 * xv
  1040.     height = 1.0 - 2 * yv
  1041.     myview = [xv+xAxis, yv+yAxis, width, height] 
  1042.  
  1043.     ;  Create the view.
  1044.     ;
  1045.     oView = OBJ_NEW('idlgrview', PROJECTION=2, EYE=3, $
  1046.         ZCLIP=[1.5,-1.5], VIEW=myview, COLOR=[0,0,0])
  1047.  
  1048.     ;  Create the model tree.
  1049.     ;
  1050.     oTopModel = OBJ_NEW('idlgrmodel')
  1051.     oView->Add, oTopModel
  1052.     
  1053.     ;  Scale the top model to fit the viewing area.
  1054.     ;
  1055.     sct = 0.7
  1056.     oTopModel->Scale, sct, sct, sct
  1057.  
  1058.     oStaticModel = OBJ_NEW('idlgrmodel')
  1059.     oStaticRotationModel = OBJ_NEW('idlgrmodel')
  1060.     oStaticScalingModel = OBJ_NEW('idlgrmodel')
  1061.     oMovableModel = OBJ_NEW('idlgrmodel')
  1062.     oMovableRotationModel = OBJ_NEW('idlgrmodel')
  1063.     oMovableScalingModel = OBJ_NEW('idlgrmodel')
  1064.     oTopModel->Add, oMovableModel
  1065.     oMovableModel->Add, oMovableRotationModel
  1066.     oMovableRotationModel->Add, oMovableScalingModel
  1067.     oTopModel->Add, oStaticModel
  1068.     oStaticModel->Add, oStaticRotationModel
  1069.     oStaticRotationModel->Add, oStaticScalingModel
  1070.  
  1071.     ;  Create the model arrays (dimension is nFrames)
  1072.     ;
  1073.     oStaticModelArray = OBJARR(nframes)
  1074.     oMovableModelArray = OBJARR(nframes)
  1075.  
  1076.     for i = 0,nframes-1 do begin
  1077.         oStaticModelArray(i) = OBJ_NEW('idlgrmodel')
  1078.         oMovableModelArray(i) = OBJ_NEW('idlgrmodel')
  1079.         oStaticScalingModel->Add, oStaticModelArray(i)
  1080.         oMovableScalingModel->Add, oMovableModelArray(i)
  1081.         oMovableModelArray(i)->SetProperty, HIDE=1
  1082.     endfor
  1083.  
  1084.     ;  Create the surface data from the vibrating membrane
  1085.     ;  function.
  1086.     ;
  1087.     z = vibmem(nframes, 0)
  1088.     sz = SIZE(z)
  1089.     maxx = sz(1) - 1
  1090.     maxy = sz(2) - 1
  1091.     maxz = MAX(z, MIN=minz)
  1092.  
  1093.     ; Compute coordinate conversion to normalize.
  1094.     ;
  1095.     xs = [0+xAxis,1.0/maxx]
  1096.     ys = [0+yAxis,1.0/maxy]
  1097.  
  1098.     minz2 = minz - 1
  1099.     maxz2 = maxz + 1 
  1100.     zs = [-minz2/(maxz2-minz2)+zAxis, 1.0/(maxz2-minz2)]
  1101.  
  1102.     ; For height-fields, use the following vertex colors.
  1103.     ;
  1104.     xdimension = sz(1) 
  1105.     ydimension = sz(2)
  1106.     vertexColors = BYTARR(nframes,3,xdimension*ydimension,/nozero)
  1107.     cbins=[[255,   0,   0], $
  1108.            [255,  85,   0], $
  1109.            [255, 170,   0], $
  1110.            [255, 255,   0], $
  1111.            [170, 255,   0], $
  1112.            [ 85, 255,   0], $
  1113.            [  0, 255,   0]]
  1114.  
  1115.  
  1116.     ; Create the shades array.
  1117.     ; 
  1118.     shadesArray = FLTARR(nframes, xdimension, ydimension)
  1119.     shades2 = FLTARR(nframes, xdimension* ydimension)
  1120.     shades3 = FLTARR(nframes, xdimension* ydimension)
  1121.     temp = fltarr(xdimension, ydimension)
  1122.     zi = INTARR( 1,xdimension, ydimension)
  1123.     xtot = xdimension * ydimension
  1124.  
  1125.     ;  Shades array is  color corresponding to hte vibrating
  1126.     ;  membrane height (4-D mode).
  1127.     ;
  1128.     for i = 0, nframes-1 do begin
  1129.         temp = vibmem(nframes, i)
  1130.         shadesArray(i, 0:xdimension-1, 0:ydimension-1) = $
  1131.             temp(0:xdimension-1, 0:ydimension-1)
  1132.         shades2(i, 0:xtot-1) = temp(0:xdimension-1, 0:ydimension-1)
  1133.     endfor
  1134.  
  1135.     shadesArray2 = shadesArray
  1136.  
  1137.     ;  Shades array 2 is  color corresponding to the  bumps
  1138.     ;  function  ( 6-D mode).
  1139.     ;
  1140.     for i = 0, nframes-1 do begin
  1141.         temp = bumps(i + 40)   ; 40 is any indice for bumps function 
  1142.         shadesArray2(i, 0:xdimension-1, 0:ydimension-1) = $
  1143.             temp(0:xdimension-1, 0:ydimension-1)
  1144.         shades3(i, 0:xtot-1) = temp(0:xdimension-1, 0:ydimension-1)
  1145.     endfor
  1146.  
  1147.     maxshades = MAX(shadesArray, MIN = minshades)
  1148.  
  1149.     sat = 1.0
  1150.     val = 1.0
  1151.     maxangle = 225.0  ; ( angle is  0 < .. < 360 )
  1152.  
  1153.     ;  Create the actual vertexcolors array corresponding
  1154.     ;  to the vibrating membrane.
  1155.     ;
  1156.     for i = 0, nframes-1 do begin
  1157.         for j = 0, xtot-1 do begin
  1158.             angle =ROUND(  (shades2(i,j) - minshades) / $ 
  1159.                 (maxshades-minshades) * maxangle )  
  1160.              color_convert, angle, sat, val, red, green, blue, /hsv_rgb
  1161.              vertexColors(i, 0, j) = red
  1162.              vertexColors(i, 1, j) = green
  1163.              vertexColors(i, 2, j) = blue
  1164.         endfor
  1165.     endfor
  1166.  
  1167.     ;  Create the actual vertexcolors array corresponding
  1168.     ;  to the bumps function.
  1169.     ;
  1170.     vertexColors2 = vertexColors
  1171.  
  1172.     maxshades = MAX(shadesArray2, MIN = minshades)
  1173.  
  1174.     for i = 0, nframes-1 do begin
  1175.         for j = 0, xtot-1 do begin
  1176.             angle =ROUND(  (shades3(i,j) - minshades) / $ 
  1177.                 (maxshades-minshades) * maxangle )  
  1178.             color_convert, angle, sat, val, red, green, blue, /hsv_rgb
  1179.             vertexColors2(i, 0, j) = red
  1180.             vertexColors2(i, 1, j) = green
  1181.             vertexColors2(i, 2, j) = blue
  1182.         endfor
  1183.     endfor
  1184.  
  1185.     ; Create an obj array , Create 20 surfaces
  1186.     ;
  1187.     oWaveSurfaceArray = OBJARR(nframes)
  1188.     for i = 0, nframes-1 do begin
  1189.         oWaveSurfaceArray(i) = OBJ_NEW('IDLgrSurface', z, $
  1190.             STYLE=2, SHADING=0, COLOR=[60,60,255], BOTTOM=[64,192,128], $
  1191.            XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs)
  1192.         oMovableModelArray(i)->add,oWaveSurfaceArray(i)
  1193.         zt = vibmem(nframes, i)
  1194.         oWaveSurfaceArray(i)->setproperty, DATAZ=zt
  1195.     endfor
  1196.  
  1197.     ;  Create a box.
  1198.     ;
  1199.     x = [ 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, $
  1200.           1, 1, 0, 1, 1   ]
  1201.     y = [ 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, $
  1202.           1, 1, 1, 1, 0   ]
  1203.     z = [ 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, $
  1204.           1, 0, 0, 0, 0   ]
  1205.  
  1206.     x2 = [ 0.0, 0.0, 0.0, 0.0, 0.0]
  1207.     y2 = [ 0.0, 0.0, 0.0, 0.0, 0.0]
  1208.     z2 = [ 0.0, 0.0, 0.0, 0.0, 0.0]
  1209.     x3 = FINDGEN(5)
  1210.     y3 = FINDGEN(5)
  1211.     z3 = FINDGEN(5)
  1212.  
  1213.     if (box EQ 1) then begin
  1214.         olineArray = objarr(20)
  1215.         for i = 0, nframes-1 do begin
  1216.             olinearray(i) = OBJ_NEW('idlgrpolyline',x,y,z, $
  1217.             COLOR=[255,0,0], THICK=2)
  1218.             oStaticModelArray(i)->add,olinearray(i)
  1219.         endfor
  1220.     endif   ; of if  box
  1221.  
  1222.  
  1223.     ;  Create some light.
  1224.     ;
  1225.     m = OBJ_NEW('idlgrmodel')
  1226.     oLight1 = OBJ_NEW('IDLgrLight', LOC=[2,2,2], TYPE=1)
  1227.     m->add,oLight1
  1228.     oLight2 = OBJ_NEW('IDLgrLight', TYPE=0, INTENSITY=0.5)
  1229.     m->add,oLight2
  1230.     OView->add,m
  1231.  
  1232.  
  1233.     ;  Create a solid line style
  1234.     ;
  1235.     for i = 0, nframes-1 do begin
  1236.         oWaveSurfaceArray(i)->SetProperty, LINESTYLE=4294967295L
  1237.     endfor
  1238.  
  1239.     ;  Rotate and translate the surfaces
  1240.     ;  Show them one by one
  1241.     ;
  1242.     for i = 0, nframes-1  do begin
  1243.         oMovableModelArray(i)->rotate,[1,0,0],-90
  1244.         oMovableModelArray(i)->rotate,[0,1,0],30
  1245.         oMovableModelArray(i)->rotate,[1,0,0],30
  1246.     endfor
  1247.  
  1248.     ;  Get the initial transform, to be used when reset.
  1249.     ;
  1250.     oMovableModelArray(0)->GetProperty, TRANSFORM=initTransform
  1251.     oMovableModelArray(0)->GetProperty, TRANSFORM=t
  1252.  
  1253.     ;  Add the trackball object for interactive change
  1254.     ;  of the scene orientation.
  1255.     ;
  1256.     oTrack = OBJ_NEW('Trackball', [xdim/2.0, ydim/2.0], xdim/2.0)
  1257.  
  1258.     oContainer = OBJ_NEW('IDLgrContainer')
  1259.     oContainer->Add, oView
  1260.     oContainer->Add, oTrack
  1261.  
  1262.  
  1263.     ; Save information into the structure
  1264.     ;
  1265.     initStr = { $
  1266.         Nframes : nframes, $
  1267.         Xdim : xdim, $
  1268.         Ydim : ydim, $
  1269.         OTopModel: oTopModel, $
  1270.         OTrack: oTrack, $
  1271.         OContainer: oContainer, $
  1272.         OMovableModel: oMovableModel, $
  1273.         OMovableRotationModel: oMovableRotationModel, $
  1274.         OMovableScalingModel: oMovableScalingModel, $
  1275.         OMovableModelArray: oMovableModelArray, $
  1276.         OWaveSurfaceArray: oWaveSurfaceArray, $
  1277.         OView: oView, $
  1278.         OStaticModelArray: oStaticModelArray, $
  1279.         VertexColors: vertexColors, $
  1280.         VertexColors2: vertexColors2, $
  1281.         Xtot : xtot, $
  1282.         InitTransform : initTransform $
  1283.     }  
  1284.  
  1285.     RETURN, initStr 
  1286.  
  1287. end     ;   of iniobj.pro
  1288.  
  1289.  
  1290.  
  1291. pro vib_SetShades, $
  1292.     initial, $      ; IN: initial frame index
  1293.     final, $        ; IN: final frame index
  1294.     event           ; IN: event structure
  1295.  
  1296.     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1297.  
  1298.     tempColor = INTARR( 3, info.xtot)
  1299.  
  1300.     if (initial LT final) then begin
  1301.         for i = initial, final do begin
  1302.             tempColor(0:2, 0:info.xtot-1) = $
  1303.                 info.vertexColors(i, 0:2, 0:info.xtot-1)
  1304.             info.oWaveSurfaceArray(i)->setproperty, $
  1305.                 VERT_COLORS=tempColor
  1306.         endfor
  1307.     endif else begin
  1308.         for i = initial, final, -1 do begin
  1309.             tempColor(0:2, 0:info.xtot-1) = $
  1310.                 info.vertexColors2(i, 0:2, 0:info.xtot-1)
  1311.             info.oWaveSurfaceArray(i)->setproperty, $
  1312.                 VERT_COLORS=tempColor
  1313.         endfor
  1314.     endelse
  1315.  
  1316.     info.drawWindowObjID->draw,info.oView
  1317.  
  1318.     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1319.  
  1320. end   ; of vib_SetShades
  1321.  
  1322. ; -----------------------------------------------------------------------------
  1323. ;
  1324. ;  Purpose:  Toggle the vertex off and vertex on button.
  1325. ;
  1326. function Toggle_state, $
  1327.     wid          ;  IN: widget identifer
  1328.  
  1329.     WIDGET_CONTROL, wid, GET_VALUE = name
  1330.  
  1331.     s = STRPOS(name,'(off)')
  1332.  
  1333.     if (s NE -1) then begin
  1334.         strput,name,'(on )',s
  1335.         ret = 1
  1336.     endif else begin
  1337.         s = strpos(name,'(on )')
  1338.         strput,name,'(off)',s
  1339.         ret = 0
  1340.     endelse
  1341.  
  1342.     WIDGET_CONTROL, wid, SET_VALUE = name
  1343.  
  1344.     RETURN, ret
  1345. end
  1346.  
  1347. ; -----------------------------------------------------------------------------
  1348. ;
  1349. ;  Purpose:  Main event handler.
  1350. ;
  1351. pro vibmembr_event, $
  1352.     event      ; IN: event structure
  1353.  
  1354.     ;  Quit the application using the close box.
  1355.     ;
  1356.     if (TAG_NAMES(event, /STRUCTURE_NAME) EQ $
  1357.         'WIDGET_KILL_REQUEST') then begin
  1358.         WIDGET_CONTROL, event.top, /DESTROY
  1359.         RETURN
  1360.     endif
  1361.  
  1362.     ;  Open a widget message if the user try to quit
  1363.     ;  using the close box (not the quit button of the application).
  1364.     ;
  1365.     if (TAG_NAMES(Event, /STRUCTURE_NAME) eq 'WIDGET_KILL_REQUEST') $
  1366.         then begin
  1367.         v = WIDGET_MESSAGE('Use the File/Quit menu item to ' + $
  1368.             'close this application.')
  1369.     endif
  1370.  
  1371.  
  1372.     case WIDGET_INFO(event.id,/NAME) of
  1373.  
  1374.         ; Now handle the button events
  1375.         ;
  1376.         'BUTTON' : begin
  1377.  
  1378.             ;  Get the event user value and branch to that event.
  1379.             ;
  1380.             WIDGET_CONTROL, event.id, GET_UVALUE=uval
  1381.  
  1382.             case uval of
  1383.  
  1384.                 ;  Change the surface into a wire style.
  1385.                 ;
  1386.                 'WIRE' : begin
  1387.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1388.                     stylestring = 'Wire'
  1389.                     info.stylestring = 'Wire'
  1390.  
  1391.                     for i = 0, info.nframes-1  do begin
  1392.                         info.oWaveSurfaceArray(i)->SetProperty, STYLE=1
  1393.                     endfor
  1394.  
  1395.                     info.dragq = 0
  1396.                     info.drawWindowObjID->SetProperty, QUALITY=info.dragq
  1397.                     info.drawWindowObjID->Draw, info.oView    
  1398.                     WIDGET_CONTROL, info.wSolidButton, SENSITIVE=1
  1399.                     WIDGET_CONTROL, info.wWireButton, SENSITIVE=0
  1400.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1401.                 end  ; of WIRE
  1402.  
  1403.                 ;  Change the surface into a solid style.
  1404.                 ;
  1405.                 'SOLID' : begin
  1406.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1407.                     stylestring = 'Solid'
  1408.                     info.stylestring = 'Solid'
  1409.  
  1410.                     for i = 0, info.nframes-1  do begin
  1411.                         info.oWaveSurfaceArray(i)->SetProperty, STYLE=2
  1412.                     endfor
  1413.  
  1414.                     WIDGET_CONTROL, info.wSolidButton, SENSITIVE=0
  1415.                     WIDGET_CONTROL, info.wWireButton, SENSITIVE=1
  1416.  
  1417.                     if (info.dragq EQ 0) then begin
  1418.                         info.dragq = 2
  1419.                         info.drawWindowObjID->SetProperty, QUALITY=info.dragq
  1420.                     endif else if (info.dragq EQ 1) then begin
  1421.                         WIDGET_CONTROL, info.wMediumButton, sensitive = 0
  1422.                     endif else begin
  1423.                         WIDGET_CONTROL, info.wHighButton, sensitive = 0
  1424.                     endelse
  1425.  
  1426.                     info.drawWindowObjID->draw,info.oView    
  1427.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1428.  
  1429.                 end  ;     of  SOLID
  1430.  
  1431.                 ;  Change the shading to flat.
  1432.                 ;
  1433.                 'FLAT' : begin
  1434.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1435.                     shadingstring = 'Flat'
  1436.                     info.shadingstring = 'Flat'
  1437.  
  1438.                     for i = 0, info.nframes-1  do begin
  1439.                         info.oWaveSurfaceArray(i)->SetProperty, SHADING=0
  1440.                     endfor
  1441.  
  1442.                     info.drawWindowObjID->draw,info.oView    
  1443.                     WIDGET_CONTROL, info.wFlatButton, SENSITIVE=0
  1444.                     WIDGET_CONTROL, info.wGouraudButton, SENSITIVE=1
  1445.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1446.  
  1447.                 end  ;     of  FLAT
  1448.  
  1449.                 ;  Change the shading to Gouraud.
  1450.                 ;
  1451.                 'GOURAUD' : begin
  1452.                      WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1453.  
  1454.                     for i = 0, info.nframes-1  do begin
  1455.                         info.oWaveSurfaceArray(i)->SetProperty, SHADING=1
  1456.                     endfor
  1457.  
  1458.                     info.drawWindowObjID->draw,info.oView    
  1459.                     shadingstring = 'Gouraud'
  1460.                     info.shadingstring = 'Gouraud'
  1461.                     WIDGET_CONTROL, info.wFlatButton, SENSITIVE=1
  1462.                     WIDGET_CONTROL, info.wGouraudButton, SENSITIVE=0
  1463.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1464.  
  1465.                 end  ;     of  GOURAUD
  1466.  
  1467.                 ;  Change the surface to show 4 dimensions.
  1468.                 ;
  1469.                 'FOURD' : begin
  1470.  
  1471.                     ;  If the vertex colors are on, set the shade 
  1472.                     ;  frames in order,
  1473.                     ;  hence showing the surface height.
  1474.                     ;
  1475.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1476.                     WIDGET_CONTROL, info.wNoColorButton, SENSITIVE=1
  1477.                     WIDGET_CONTROL, info.wFourDButton, SENSITIVE=0
  1478.                     WIDGET_CONTROL, info.wFiveDButton, SENSITIVE=1
  1479.                     nframes = info.nframes
  1480.  
  1481.                     nFrames = info.nFrames
  1482.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1483.                     vib_SetShades, 0, nframes-1, event
  1484.  
  1485.                 end  ;     of  FOURD
  1486.  
  1487.                 ;  Change the surface to show 5 dimensions.
  1488.                 ;
  1489.                 'FIVED' : begin
  1490.  
  1491.                     ;  Set the shades colors to show the
  1492.                     ;  'bumps' function values.
  1493.                     ;  Toggle the vertex color button to on.
  1494.                     ;
  1495.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1496.  
  1497.                     WIDGET_CONTROL, info.wNoColorButton, SENSITIVE=1
  1498.                     WIDGET_CONTROL, info.wFourDButton, SENSITIVE=1
  1499.                     WIDGET_CONTROL, info.wFiveDButton, SENSITIVE=0
  1500.  
  1501.                     nFrames = info.nFrames
  1502.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1503.                     vib_SetShades, nframes-1, 0, event
  1504.  
  1505.                 end  ;     of  FIVED
  1506.  
  1507.                 ;  Set the surface to be monochromatic (one color).
  1508.                 ;
  1509.                 'NOCOLOR' : begin
  1510.  
  1511.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1512.  
  1513.                     WIDGET_CONTROL, info.wNoColorButton, SENSITIVE=0
  1514.                     WIDGET_CONTROL, info.wFourDButton, SENSITIVE=1
  1515.                     WIDGET_CONTROL, info.wFiveDButton, SENSITIVE=1
  1516.  
  1517.  
  1518.                     tempColor = INTARR( 3, info.xtot)
  1519.                     topColor = INTARR(3)
  1520.                     bottomColor = INTARR(3)
  1521.                     info.oWaveSurfaceArray(0)->getproperty, COLOR=topColor
  1522.                     info.oWaveSurfaceArray(0)->getproperty, BOTTOM=bottomColor
  1523.                     nframes = info.nframes
  1524.       
  1525.                     for i = 0, info.nframes-1 DO begin
  1526.                         info.oWaveSurfaceArray(i)->SetProperty, $
  1527.                             VERT_COLORS=0
  1528.                         info.oWaveSurfaceArray(i)->SetProperty, $
  1529.                             COLOR=topColor
  1530.                         info.oWaveSurfaceArray(i)->SetProperty, $
  1531.                             BOTTOM=bottomColor
  1532.                     endfor
  1533.  
  1534.                     info.drawWindowObjID->draw,info.oView
  1535.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1536.  
  1537.                 end   ; of NOCOLOR
  1538.  
  1539.                 ;  Set drag quality to low.
  1540.                 ;
  1541.                 'LOW' : begin
  1542.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1543.                     child = WIDGET_INFO( info.wCWBase, /CHILD)
  1544.                     WIDGET_CONTROL, child, GET_UVALUE = state, /NO_COPY
  1545.                     info.dragq = 0
  1546.                     state.dragq = 0
  1547.                     WIDGET_CONTROL, child, SET_UVALUE = state, /NO_COPY
  1548.                     WIDGET_CONTROL, info.wLowButton, SENSITIVE=0
  1549.                     WIDGET_CONTROL, info.wMediumButton, SENSITIVE=1
  1550.                     WIDGET_CONTROL, info.wHighButton, SENSITIVE=1
  1551.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1552.                 end   ; of  LOW
  1553.  
  1554.                 ;  Set drag quality to medium.
  1555.                 ;
  1556.                 'MEDIUM' : begin
  1557.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1558.                     child = WIDGET_INFO( info.wCWBase, /CHILD)
  1559.                     WIDGET_CONTROL, child, GET_UVALUE = state, /NO_COPY
  1560.                     info.dragq = 1
  1561.                     state.dragq = 1
  1562.                     WIDGET_CONTROL, child, SET_UVALUE = state, /NO_COPY
  1563.                     WIDGET_CONTROL, info.wLowButton, SENSITIVE=1
  1564.                     WIDGET_CONTROL, info.wMediumButton, SENSITIVE=0
  1565.                     WIDGET_CONTROL, info.wHighButton, SENSITIVE=1
  1566.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1567.                 end   ; of  MEDIUM
  1568.  
  1569.                 ;  Set drag quality to high.
  1570.                 ;
  1571.                 'HIGH' : begin
  1572.                     WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
  1573.                     child = WIDGET_INFO( info.wCWBase, /CHILD)
  1574.                     WIDGET_CONTROL, child, GET_UVALUE = state, /NO_COPY
  1575.                     info.dragq = 2
  1576.                     state.dragq = 2
  1577.                     WIDGET_CONTROL, child, SET_UVALUE = state, /NO_COPY
  1578.                     WIDGET_CONTROL, info.wLowButton, SENSITIVE=1
  1579.                     WIDGET_CONTROL, info.wMediumButton, SENSITIVE=1
  1580.                     WIDGET_CONTROL, info.wHighButton, SENSITIVE=0
  1581.                     WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
  1582.                 end   ; of  HIGH
  1583.  
  1584.                 ;  Display the information file.
  1585.                 ;
  1586.                 'INFO' : begin
  1587.                     if (Xregistered('XDisplayFile') NE 0) then RETURN
  1588.                     XDisplayFile, filepath("vibmembr.txt", $
  1589.                         SUBDIR=['examples', 'demo', 'demotext']), $
  1590.                         DONE_BUTTON='Done', $
  1591.                         TITLE="About intereactive 6-D visualizations", $
  1592.                         GROUP=event.top, WIDTH=55, HEIGHT=14
  1593.                 end   ; of  INFO
  1594.  
  1595.                 ;  Quit thie application.
  1596.                 ;
  1597.                 'QUIT' : begin
  1598.                     WIDGET_CONTROL, event.top, /DESTROY
  1599.                     RETURN
  1600.                 end   ; of  QUIT
  1601.  
  1602.             endcase  ; of case uval in BUTTON
  1603.  
  1604.         end   ; of BUTTON case
  1605.  
  1606.         ELSE :   ; do nothing
  1607.  
  1608.     endcase   ; of case widget_info(name)
  1609.  
  1610. end  ; of vibmembr_event
  1611.  
  1612. ; -----------------------------------------------------------------------------
  1613. ;
  1614. ;  Purpose:   Cleanup procedure. Destroy the objects and
  1615. ;             restore the previous color table.
  1616. ;
  1617. pro vibmembr_cleanup, $
  1618.     wTopBase         ; IN: top level base identifier
  1619.  
  1620.     WIDGET_CONTROL, wTopBase, GET_UVALUE=info, /NO_COPY
  1621.  
  1622.     ;  Restore the color table
  1623.     ;
  1624.     TVLCT, info.colorTable
  1625.  
  1626.     ;  Destroy the top objects
  1627.     ;
  1628.     OBJ_DESTROY, info.oView
  1629.  
  1630.     OBJ_DESTROY, info.oTrack
  1631.     OBJ_DESTROY, info.oContainer
  1632.  
  1633.     ;  Map the group leader base if it exists.
  1634.     ;
  1635.     if (WIDGET_INFO(info.groupBase, /VALID_ID)) then $
  1636.         WIDGET_CONTROL, info.groupBase, /MAP
  1637.  
  1638. end ; of vibmembr_cleanup
  1639.  
  1640. ; -----------------------------------------------------------------------------
  1641. ;
  1642. ;  Purpose:   Animate a series of surface objects (in IDL 5.0).
  1643. ;             The scheme is to precompute the surface height for
  1644. ;             n frames. The 'animation' is made by displaying
  1645. ;             successively each frames ( or objects)
  1646. ;
  1647. pro d_vibmembr, $
  1648.     Box = box, $       ; IN: (opt) create a box arou d the surface
  1649.     GROUP=group, $     ; IN: (opt) Group leader
  1650.     APPTLB = appTLB    ; OUT: (opt) TLB of this application
  1651.  
  1652.     ; Check the validity of the group identifier.
  1653.     ;
  1654.     ngroup = N_ELEMENTS(group)
  1655.     if (ngroup NE 0) then begin
  1656.         check = WIDGET_INFO(group, /VALID_ID)
  1657.         if (check NE 1) then begin
  1658.             print,'Error, the group identifier is not valid'
  1659.             print, 'Return to the main application'
  1660.             RETURN
  1661.         endif
  1662.         groupBase = group
  1663.     endif else groupBase = 0L
  1664.  
  1665.     checkBox = N_ELEMENTS(box)
  1666.  
  1667.     ;  Save the color table
  1668.     ;
  1669.     TVLCT, savedR, savedG, savedB, /GET
  1670.     colorTable = [ [savedR], [savedG], [savedB] ]
  1671.  
  1672.  
  1673.     ;  Make the system to have a maximum of 256 colors.
  1674.     ;
  1675.     if ((( !D.NAME EQ 'X') OR (!D.NAME EQ 'MAC')) $
  1676.        AND (!D.N_COLORS GE 256L)) then $
  1677.        DEVICE, PSEUDO_COLOR=8
  1678.     
  1679.     DEVICE, DECOMPOSED=0, BYPASS_TRANSLATION=0
  1680.  
  1681.     ;  Determine hardware display size.
  1682.     ;
  1683.     DEVICE, GET_SCREEN_SIZE=screenSize
  1684.  
  1685.     ;  Make the drawing area proportional to the 
  1686.     ;  screen size.
  1687.     ;
  1688.     drawXSize = 0.6 * screenSize(0)
  1689.     drawYSize = 0.8 * drawXSize
  1690.  
  1691.     ;  Get the tips.
  1692.     ;
  1693.     sText = getTips(filepath('vibmembr.tip', $
  1694.         SUBDIR=['examples','demo', 'demotext']) )
  1695.  
  1696.     ;  Initialize parameter / constants
  1697.     ;
  1698.     nframes = 20     ; number of frames 
  1699.     reset = 1         ; have a reset button in the compound widget)
  1700.     xdim = drawXSize
  1701.     ydim = drawYSize
  1702.  
  1703.     ;  Initialize all the objects
  1704.     ;
  1705.     objectStr = iniobj(nframes, xdim, ydim, Box = checkbox)
  1706.  
  1707.     ;  Create widgets.
  1708.     ;
  1709.     if (ngroup EQ 0) then begin
  1710.         wTopBase = WIDGET_BASE(/COLUMN, $
  1711.             TLB_FRAME_ATTR=1, MBAR=barbase, $
  1712.             XPAD=0, YPAD=0, $
  1713.             /TLB_KILL_REQUEST_EVENTS, $
  1714.             TITLE="Vibrating Membrane")
  1715.     endif else begin
  1716.         wTopBase = WIDGET_BASE(/COLUMN, $
  1717.             GROUP_LEADER=parent, $
  1718.             XPAD=0, YPAD=0, $
  1719.             TLB_FRAME_ATTR=1, MBAR=barbase, $
  1720.             /TLB_KILL_REQUEST_EVENTS, $
  1721.             TITLE="Vibrating Membrane")
  1722.     endelse
  1723.  
  1724.         ;  Create the file menu bar item that contains the quit button.
  1725.         ;
  1726.         wFileButton = WIDGET_BUTTON(barbase,Value = 'File', /MENU)
  1727.  
  1728.             wQuitButton = WIDGET_BUTTON(wFileButton, $
  1729.                 VALUE='Quit', UVALUE='QUIT')
  1730.  
  1731.         ;  Create the option menu .
  1732.         ;
  1733.         wOptionButton = WIDGET_BUTTON(barbase, VALUE='Options', /MENU)
  1734.  
  1735.             wStyleButton = WIDGET_BUTTON(wOptionButton, $
  1736.                 VALUE='Style', UVALUE='Style', /MENU)
  1737.  
  1738.                 wWireButton = WIDGET_BUTTON(wStyleButton, $
  1739.                     VALUE='Wire', UVALUE='WIRE')
  1740.  
  1741.                 wSolidButton = WIDGET_BUTTON(wStyleButton, $
  1742.                     VALUE='Solid', UVALUE='SOLID')
  1743.  
  1744.             wShadingButton = WIDGET_BUTTON(wOptionButton, $
  1745.                 VALUE='Shading', UVALUE='Shading', /MENU)
  1746.  
  1747.                 wFlatButton = WIDGET_BUTTON(wShadingButton, $
  1748.                     VALUE='Flat', UVALUE='FLAT')
  1749.  
  1750.                 wGouraudButton = WIDGET_BUTTON(wShadingButton, $
  1751.                     VALUE='Gouraud', UVALUE='GOURAUD')
  1752.  
  1753.             wQualityButton = WIDGET_BUTTON(wOptionButton, $
  1754.                 VALUE='Drag Quality', UVALUE='QUALITY', /MENU)
  1755.  
  1756.                 wLowButton = WIDGET_BUTTON(wQualityButton, $
  1757.                     VALUE='Low', UVALUE='LOW')
  1758.  
  1759.                 wMediumButton = WIDGET_BUTTON(wQualityButton, $
  1760.                     VALUE='Medium', UVALUE='MEDIUM')
  1761.  
  1762.                 wHighButton = WIDGET_BUTTON(wQualityButton, $
  1763.                     VALUE='High', UVALUE='HIGH')
  1764.  
  1765.             wVertexButton = WIDGET_BUTTON(wOptionButton, $
  1766.                 VALUE='Vertex Colors', /MENU, UVALUE='VERTEX')
  1767.  
  1768.                 wNoColorButton = WIDGET_BUTTON(wVertexButton, $
  1769.                     VALUE='Monochromatic', UVALUE='NOCOLOR')
  1770.  
  1771.                 wFourDButton = WIDGET_BUTTON(wVertexButton, $
  1772.                     VALUE='4 Dimensions', UVALUE='FOURD')
  1773.  
  1774.                 wFiveDButton = WIDGET_BUTTON(wVertexButton, $
  1775.                     VALUE='5 Dimensions', UVALUE='FIVED')
  1776.  
  1777.  
  1778.         ;  Create the menu bar item help that contains the about button.
  1779.         ;
  1780.         wHelpButton = WIDGET_BUTTON(barbase,Value = 'About', /HELP, /Menu)
  1781.  
  1782.             wAboutButton = WIDGET_BUTTON(wHelpButton, $
  1783.                 VALUE='About Vibrating Membrane', UVALUE='INFO')
  1784.  
  1785.         ;  Call the compound widget that creates the core
  1786.         ;  of the animation tool.
  1787.         ;
  1788.         wCWBase = cw_iat(wTopBase, $
  1789.             objectStr.oStaticModelArray, objectStr.oMovableModelArray, $
  1790.             objectStr.oMovableModel, objectStr.oMovableRotationModel, $
  1791.             objectStr.oMovableScalingModel, $
  1792.             objectStr.oView,  $
  1793.             objectStr.oTrack, $
  1794.             objectStr.oContainer, nframes, $
  1795.             XSIZE=xdim, YSIZE=ydim, $
  1796.             RESET=reset, STATUS=cwStatus)
  1797.  
  1798.         ;  Check the status of the cw_iat
  1799.         ;
  1800.         if (cwStatus EQ 0) then begin 
  1801.             MESSAGE,'The creation of the compound widget was not successful'
  1802.             RETURN
  1803.         endif
  1804.  
  1805.         ;  Create tips texts.
  1806.         ;
  1807.         wStatusBase = WIDGET_BASE(wTopBase, MAP=0, /ROW)
  1808.  
  1809.             nWidgets = 2
  1810.             wText = LONARR(nWidgets)
  1811.             widTips, wStatusBase, sText.text, XSIZE=36, $
  1812.                 YSIZE=3, NWIDGETS=nWidgets, wText
  1813.  
  1814.     ;  Now, all the widget have been created....
  1815.     ;  Realize the widget hierarchy.
  1816.     ;
  1817.     WIDGET_CONTROL, wTopBase, /REALIZE
  1818.  
  1819.     ;  Returns the top level base to the APPTLB keyword.
  1820.     ;
  1821.     appTLB = wtopBase
  1822.  
  1823.     ;  Size the tips widgets.
  1824.     ;
  1825.     sizeTips, wTopBase, wText, wStatusBase
  1826.  
  1827.     ;  Get the info structure of the compound widget  CW_IAT
  1828.     ;
  1829.     child = WIDGET_INFO( wCWBase, /CHILD)
  1830.     WIDGET_CONTROL, child, GET_UVALUE = state, /NO_COPY
  1831.  
  1832.     ;  Get the base that has the TIMER user value.
  1833.     ;  Make the stop flag to 0 ( not stopped)
  1834.     ;  so that we can animate at start up.
  1835.     ;
  1836.     wButtonBase = state.wButtonBase
  1837.     state.stopFlag = 0
  1838.  
  1839.     ;  Get the window object  of CW_IAT.
  1840.     ;
  1841.     wAreaDraw = state.wAreaDraw
  1842.     WIDGET_CONTROL, state.wRightBase, GET_UVALUE = temp, /NO_COPY
  1843.     drawWindowObjID = temp
  1844.     WIDGET_CONTROL, state.wRightBase, SET_UVALUE = temp, /NO_COPY
  1845.  
  1846.     ;  Desensitize the frame indicator slider.
  1847.     ;
  1848.     WIDGET_CONTROL, state.wFramesIndicatorSlider, SENSITIVE=0
  1849.  
  1850.     ;  Set the play forward button on, and the stop to off.
  1851.     ;
  1852.     WIDGET_CONTROL, state.wStopButton, SET_VALUE=state.BMB.stop
  1853.     WIDGET_CONTROL, state.wPlayFButton, SET_VALUE=state.BMB.forwardOn
  1854.  
  1855.     ;  Show each seperate frames.
  1856.     ;
  1857.     tempColor = INTARR( 3, objectStr.xtot)
  1858.     for i = 0, nframes-1 do begin
  1859.         objectStr.oMovableModelArray(i)->SetProperty, HIDE=0
  1860.         objectStr.oWaveSurfaceArray(i)->SetProperty, SHADING=1
  1861.  
  1862.             tempColor(0:2, 0:objectStr.xtot-1) = $
  1863.                 objectStr.vertexColors(i, 0:2, 0:objectStr.xtot-1)
  1864.  
  1865.         objectStr.oWaveSurfaceArray(i)->SetProperty, $
  1866.             VERT_COLORS=tempColor
  1867.         drawWindowObjID->draw,objectStr.oView
  1868.         objectStr.oMovableModelArray(i)->SetProperty, HIDE=1
  1869.         WIDGET_CONTROL, state.wFramesIndicatorSlider, SET_VALUE=i
  1870.     endfor
  1871.  
  1872.  
  1873.     ;  Set the frame indicator slider to 0.
  1874.     ;
  1875.     WIDGET_CONTROL, state.wFramesIndicatorSlider, $
  1876.        SET_SLIDER_MAX=nframes-1
  1877.     WIDGET_CONTROL, state.wFramesIndicatorSlider, SET_VALUE=0
  1878.  
  1879.     ;  Get the drag quality as set by cw_iat.
  1880.     ;  And the compound widget toplevel base ID.
  1881.     ;
  1882.     wCWBase = state.wCWBase
  1883.     dragq = state.dragq
  1884.  
  1885.     ;  Sensitize the compound widget.
  1886.     ;
  1887.     WIDGET_CONTROL, child, SET_UVALUE=state, /NO_COPY
  1888.     WIDGET_CONTROL, wCWBase, SENSITIVE=1
  1889.  
  1890.     ;  Create the info structure of the main application.
  1891.     ;
  1892.     info = { $
  1893.         dragq: dragq, $                     ; Drag quality: 0=low, 1=med. 2=high
  1894.         ColorTable: colorTable, $           ; Color table to restore
  1895.         facing: 'BOTH', $                   ; Showing both sides
  1896.         wAreaDraw: wAreaDraw, $             ; Widget draw ID
  1897.         OWaveSurfaceArray:  $
  1898.             objectStr.oWaveSurfaceArray, $  ; Surface object array
  1899.         OView: objectStr.oView, $           ; Main view object
  1900.         OTrack: objectStr.oTrack, $         ; Trackball object
  1901.         OContainer: objectStr.oContainer, $ ; Container object
  1902.         oStaticModelArray: $
  1903.             objectStr.oStaticModelArray, $  ; Models
  1904.         OMovableModelArray: $
  1905.             objectStr.oMovableModelArray, $
  1906.         OMovableModel:  $
  1907.             objectStr.oMovableModel, $
  1908.         OMovableRotationModel: $
  1909.             objectStr.oMovableRotationModel, $
  1910.         OMovableScalingModel: $
  1911.             objectStr.oMovableScalingModel, $
  1912.         VertexColors: $
  1913.             objectStr.vertexColors, $       ; Vertices colors (4-D)
  1914.         VertexColors2:  $
  1915.             objectStr.vertexColors2, $      ; Vertices colors (5-D)
  1916.         DrawWindowObjID: drawWindowObjID, $ ; Window object
  1917.         Barbase : barbase, $                ; Menu bar base ID
  1918.         WTopBase: wTopBase, $               ; Top level base
  1919.         WCWBase: wCWBase, $                 ; Compound widget top level base
  1920.         WQuitButton: wQuitButton, $         ; Functionality button IDs
  1921.         WWireButton: wWireButton, $
  1922.         WSolidButton: wSolidButton, $
  1923.         WFlatButton: wFlatButton, $
  1924.         WGouraudButton: wGouraudButton, $
  1925.         WNoColorButton: wNoColorButton, $
  1926.         WFourdButton: wFourDButton, $
  1927.         WFivedButton: wFiveDButton, $
  1928.         WVertexButton: wVertexButton, $
  1929.         WLowButton: wLowButton, $
  1930.         WMediumButton: wMediumButton, $
  1931.         WHighButton: wHighButton, $
  1932.         Stylestring : 'Solid', $            ; String indicating the style
  1933.         Shadingstring : 'Flat', $           ; String indicating the shading
  1934.         Nframes: nframes, $                 ; Number of frames
  1935.         Xtot : objectStr.xtot, $            ; Product of x dim by y dim of data set.
  1936.         groupBase: groupBase $              ; Base of Group Leader
  1937.      } 
  1938.  
  1939.    WIDGET_CONTROL, wTopBase, SET_UVALUE=info, /NO_COPY
  1940.  
  1941.    ;  Desensitize the stop button.
  1942.    ;
  1943.    WIDGET_CONTROL, wFourDButton, SENSITIVE=0
  1944.    WIDGET_CONTROL, wGouraudButton, SENSITIVE=0
  1945.    WIDGET_CONTROL, wSolidButton, SENSITIVE=0
  1946.  
  1947.    ;  Desensitize the medium and high drag quality buttons.
  1948.    ;
  1949.    WIDGET_CONTROL, wLowButton, SENSITIVE=1
  1950.    WIDGET_CONTROL, wMediumButton, SENSITIVE=1
  1951.    WIDGET_CONTROL, wHighButton, SENSITIVE=0    ; this was set in cw_iat
  1952.  
  1953.    ;  Make the kill request sensitive. This make the
  1954.    ;  event created by the quit and close button from
  1955.    ;  the opreating system to be gently recognied and processed.
  1956.    ;
  1957.    WIDGET_CONTROL, wTopBase,/TLB_KILL_REQUEST_EVENTS
  1958.  
  1959.    objectStr.oMovableModelArray(0)->SetProperty, HIDE=0
  1960.    objectStr.oStaticModelArray(0)->SetProperty, HIDE=0
  1961.  
  1962.     ;  Animate at start.
  1963.     ;
  1964.     pseudoEvent = { $
  1965.         ID: wButtonBase, $
  1966.         Top: wTopBase, $
  1967.         Handler:wCWBAse $
  1968.     }
  1969.     cw_iatEvent, pseudoEvent 
  1970.  
  1971.    XMANAGER, 'd_vibmembr', wTopBase, EVENT_HANDLER='vibmembr_event', $
  1972.        CLEANUP='vibmembr_cleanup', /NO_BLOCK
  1973.  
  1974. end
  1975.